package com.project.adapters;

import com.project.database.TableRss;
import com.project.ereader.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AdapterRssFeed extends ArrayAdapter<TableRss> {

	Context context;
	int layoutResourceId;
	TableRss[] data = null;
	public AdapterRssFeed(Context context, int layoutResourceId, TableRss[] data) {
		super(context, layoutResourceId, data);
		this.context = context;
		this.layoutResourceId = layoutResourceId;
		this.data = data;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ViewHolder holder = null;
		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);
			holder = new ViewHolder();
			holder.description = (TextView) row.findViewById(R.id.description);
			holder.link = (TextView) row.findViewById(R.id.link);
			
			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}
		TableRss rssItem = data[position];
		holder.description.setText(rssItem.getDescription());
		holder.link.setText(rssItem.getLink());
		return row;
	}

	static class ViewHolder {
		TextView description;
		TextView link;
	}

}
